<template>

  <div class="ma-content-block lg:flex justify-between p-4">

    <div class="lg:w-10/12 w-full lg:ml-4 mt-5 lg:mt-0">

      <div class="mt-5">
        <a-button @click="updateMoney">更新收益</a-button>
      </div>

      <ma-crud :options="crud" :columns="columns" ref="crudRef">

        <template #operationAfterExtend="{ record }">
          <div v-if="!checkCookieIsExpire(record.cookies_obj)">
            <a-link @click="openFinanceModal(record)">
              <template #icon>
                <icon-wechatpay/>
              </template>
              提现
            </a-link>
          </div>

        </template>
      </ma-crud>

    </div>

    <finance @onClose="onClose" ref="financeRef"/>
  </div>
</template>

<script setup>

import {ref, onMounted, reactive, computed} from 'vue'
import Api from '@/api/user'
import {Message} from "@arco-design/web-vue";
import Finance from '../user/components/finance.vue'
import {
  checkCookieIsExpire
} from '@/utils/fun'

const crudRef = ref()

function updateMoney() {
  Api.updateUserMoney().then(() => {
    Message.info("已经更新");
    crudRef.value.refresh();
  })
}


const crud = reactive({
  api: Api.benefitsList,
  showIndex: false,
  pageLayout: 'fixed',
  rowSelection: {showCheckedAll: true},
  isDbClickEdit: false,
  // 开启合计行功能
  showSummary: true,
  summary: [
    // 定义 amountA 字段加总合计
    {
      dataIndex: 'recharge_money',
      action: 'sum'
    },
    {
      dataIndex: 'income',
      action: 'sum'
    },
    {
      dataIndex: 'withdrawn',
      action: 'sum'
    },
    {
      dataIndex: 'undelivered',
      action: 'sum'
    }
  ],
  operationColumn:true,
  operationColumnWidth:100

})

const columns = [
  {
    title: '账号',
    dataIndex: 'name',
    fixed: 'left',
    width: 100
  },
  {
    title: '游戏',
    dataIndex: 'game_name',
    fixed: 'left',
    width: 100
  },
  {
    title: '绑定微信',
    dataIndex: 'wx_name',
    fixed: 'left',
    width: 100
  },
  {
    title: '所属者',
    dataIndex: 'owner',
    fixed: 'left',
    width: 100
  },
  {
    title: '成本',
    dataIndex: 'recharge_money',
    fixed: 'left',
    width: 100
  },
  {
    title: '收益',
    dataIndex: 'income',
    fixed: 'left',
    width: 100
  },
  {
    title: '已提现',
    dataIndex: 'withdrawn',
    fixed: 'left',
    width: 100
  },
  {
    title: '未提现',
    dataIndex: 'undelivered',
    fixed: 'left',
    width: 100
  },
];



const financeRef = ref()

function openFinanceModal(record) {
  financeRef.value.open(record)
}
function onClose(){
  crudRef.value.refresh()
}
</script>